import sys
import math
import typing
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5 import QtWidgets


class OldGuyDeath(QGraphicsItem):
    def __init__(self, scene):
        super(OldGuyDeath, self).__init__()
        self.root = QFileInfo(__file__).absolutePath()

        self.deathlist = []
        for i in range(6):
            self.deathlist.append(QPixmap(self.root + "/res/old_death_frame" + str(i + 1) + ".png"))

        self.i = 0  # 更新deathlist下标
        self.setVisible(False)
        self.scene = scene
        self.scene.addItem(self)

    def boundingRect(self):
        return QRectF(-self.deathlist[0].width() * 0.5, -self.deathlist[0].height() * 0.5, self.deathlist[0].width(),
                      self.deathlist[0].height())

    def paint(self, painter: QPainter, option: 'QStyleOptionGraphicsItem', widget: typing.Optional[QWidget] = ...):
        painter.drawPixmap(-self.deathlist[0].width() * 0.5, -self.deathlist[0].height() * 0.5, self.deathlist[self.i])

    def updateDeathAnimation(self):
        self.setVisible(True)
        self.i = (self.i + 1) % 6
        self.update()
